package name.bingo.bing.concurrent.red.packet.service;

import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;
import name.bingo.bing.concurrent.red.packet.dao.TRedPacketDao;
import name.bingo.bing.concurrent.red.packet.model.TRedPacket;
import name.bingo.bing.concurrent.red.packet.service.TRedPacketWriteService;
import name.bingo.common.model.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 鍐欐湇鍔″疄鐜扮被
 *
 * @author [ your email ]
 * @date 2019-03-22 11:09:52
 * Created by CodeGen .
 */
@Slf4j
@Service
public class TRedPacketWriteServiceImpl implements TRedPacketWriteService {

    @Autowired
    private TRedPacketDao tRedPacketDao;

    @Override
    public Response<Long> create(TRedPacket tRedPacket) {
        try {
            tRedPacketDao.create(tRedPacket);
            return Response.ok(tRedPacket.getId());
        } catch (Exception e) {
            log.error("failed to create t red packet, cause:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("t.red.packet.create.fail");
        }
    }

    @Override
    public Response<Boolean> update(TRedPacket tRedPacket) {
        try {
            return Response.ok(tRedPacketDao.update(tRedPacket));
        } catch (Exception e) {
            log.error("failed to update t red packet, cause:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("t.red.packet.update.fail");
        }
    }

}
